Advanced Java Programming

Image
                          Advanced Java Programming Advanced Java Programming :-   Introduction to advance java   As most of us already know that if we want to make normal applications it  can be easily built using core Java concepts. But, when it we need to develop web applications, advanced Java fundamentals, like JSP, Servlets, JDBC etc. needed, so to add capabilities and features of the application advance java is essential for developers. Through the motive of this blog is to explain about Advanced Java, I will be giving you a complete insight into the fundamental concepts of Advance Java. Figure - 1.2 If you want to see complete video on this please  have a look the video below.                              Learn with Resh u Advanced Java Programming Course ...

Complete Guide for if else Statement.

 

Complete Guide for if  else Statement.



Java has the following conditional statements:

  • Use if to specify a block of code to be executed, if a specified condition is true
  • Use else to specify a block of code to be executed, if the same condition is false
  • Use else if to specify a new condition to test, if the first condition is false
  • Use switch to specify many alternative blocks of code to be executed

Java supports the usual logical conditions from mathematics:
  • Less than: a < b
  • Less than or equal to: a <= b
  • Greater than: a > b
  • Greater than or equal to: a >= b
  • Equal to a == b
  • Not Equal to: a != b
You can use these conditions to perform different actions for different decisions.




The if Statement
Use the if statement to specify a block of Java code to be executed if a condition is true.

Syntax

if (condition) {
  // block of code to be executed if the condition is true
}


Note that if is in lowercase letters. Uppercase letters (If or IF) will generate an error.


In the example below, we test two values to find out if 21 is greater than 19. If the condition is true, print some text:


Example

if (21 > 19) {
  System.out.println("21 is greater than 19");
}
As Same way we can also test variables:


Example

int x = 22;
int y = 20;
if (x > y) {
  System.out.println("x is greater than y");
}

Example explained

In the example above we use two variables, x and y, to test whether x is greater than y (using the > operator). As x is 22, and y is 20, and we know that 22 is greater than 20, we print to the screen that "x is greater than y".      


No turn comes for 


The else Statement

We use else statement to specify a block of code to be executed if the condition in if  is false.   


Syntax

if (condition) {
  // block of code to be executed if the condition is true
} else {
  // block of code to be executed if the condition is false 

}


Example

int number = 10;
if (number > 18) {
  System.out.println("Hello.");
} else {
  System.out.println("Bye.");
} 

// Outputs "Bye."           


Example explained

In the example above, number (10) is less than 18, so the condition is false. Because of this, we move on to the else condition and print to the screen "Bye". If the number was greater than 18, the program would print "Hello".

The else if Statement


We use the else if statement to specify a new condition if the first condition defined in if is false.

Syntax

if (condition1) {
  // block of code to be executed if condition1 is true
} else if (condition2) {
  // block of code to be executed if the condition1 is false and condition2 is true
} else {
  // block of code to be executed if the condition1 is false and condition2 is false
}



Example

int number = 22;
if (number < 10) {
  System.out.println("Good morning.");
} else if (number < 20) {
  System.out.println("Good day.");
} else {
  System.out.println("Good evening.");
}
// Outputs "Good evening."

Example explained

In the example above, number (22) is greater than 10, so the first condition is false. The next condition, in the else if statement, is also false, so we move on to the else condition since condition1 and condition2 is both false - and print to the screen "Good evening".
However, if the number was 14, our program would print "Good day."        



  


Please click on play and learn if else statement for free with good code example..




Recommended Posts:

·       Overriding in Java
·       Overloading in Java
·       Interfaces in Java
·       Loops in Java
·       Variables in Java

Advanced Java Programming

         Abstraction in Java
·       Encapsulation in java
·       What is Java
·       Enabling Remote Debug

Comments

Popular posts from this blog

Learn Complete OOPS Concepts in one Project

Spring Core

Polymorphism in Java Method Overriding and Method OverLoading in Java